package com.zte.purchase.control;

import com.zte.purchase.model.BrandCondition;
import com.zte.purchase.model.BrandParam;
import com.zte.purchase.model.CBrand;
import com.zte.purchase.server.IBrandServer;
import com.zte.util.OperatorLog;
import com.zte.util.PageModel;
import com.zte.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class BrandAction {

    @Autowired
    private IBrandServer brandServer;

    @RequestMapping("/brand/addBrand")
//    @OperatorLog(operate="添加品牌", module="采购管理")
    @ResponseBody
    public ResultMessage addBrand(CBrand brand){
        boolean isADD = brandServer.addBrand(brand);

        ResultMessage msg = new  ResultMessage();
        msg.setStatus(200);
        msg.setMsg("添加成功");
        msg.setFlag(true);
        msg.setData(isADD);

        return msg;
    }

    @RequestMapping("/brand/updateBrand")
//    @OperatorLog(operate="修改品牌", module="采购管理")
    @ResponseBody
    public ResultMessage updateBrand(CBrand cBrand){
        boolean isUpdate = brandServer.updateBrand(cBrand);

        ResultMessage msg = new  ResultMessage();
        msg.setStatus(200);
        msg.setMsg("修改成功");
        msg.setFlag(true);
        msg.setData(isUpdate);

        return msg;
    }

    @RequestMapping("/brand/updateBrandStatus")
//    @OperatorLog(operate="修改品牌状态", module="采购管理")
    @ResponseBody
    public ResultMessage updateBrandStatus(String brandId,String brandStatus){
        boolean isUpdate = brandServer.updateBrandStatus(brandId,brandStatus);

        ResultMessage msg = new  ResultMessage();
        msg.setStatus(200);
        msg.setMsg("修改成功");
        msg.setFlag(true);
        msg.setData(isUpdate);

        return msg;
    }

    @RequestMapping("/brand/findBrand")
    @ResponseBody
    public ResultMessage findBrand(String brandId){
        CBrand oneBrand = brandServer.findOneBrand(brandId);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(oneBrand);

        return msg;
    }

    @RequestMapping("/brand/queryBrandName")
    @ResponseBody
    public ResultMessage queryBrandName(){
        List<BrandParam> strings = brandServer.queryBrandNameList();

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(strings);

        return msg;
    }

    @RequestMapping("/brand/queryBrandPage")
//    @OperatorLog(operate="多条件查询品牌", module="采购管理")
    @ResponseBody
    public ResultMessage queryBrandPage(Integer pageNum, Integer pageSize, BrandCondition conn){
        PageModel<CBrand> model = new PageModel<CBrand>();
        model.setPageNum(pageNum);
        model.setPageSize(pageSize);

        PageModel<CBrand> pageModel = brandServer.queryBrandPage(model, conn);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(pageModel);

        return msg;

    }
}
